package com.course.controller;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import com.course.db.ChooseCourse;
import com.et.mvc.*;
import com.jspsmart.upload.SmartUpload;

import jxl.*;
import jxl.write.*;

public class ReportController extends ApplicationController {

	private ServletConfig config;
	final public void init(ServletConfig config) throws ServletException {
		  this.config = config;
		 }
	
	public String gradeCourse() throws Exception{
	
		String grade = "高一(1)";
		ChooseCourse choosecourse = new ChooseCourse();
		choosecourse.show_grade_course(grade);
		String templatepath=request.getSession().getServletContext().getRealPath("/files/template/");
		String downpath=request.getSession().getServletContext().getRealPath("/files/download/");
		
		try{
			 Workbook wb = Workbook.getWorkbook(new File(templatepath+"/gradecourse.xls"));
			 // 第二步：通过模板得到一个可写的Workbook：第一个参数是一个输出流对象,第二个参数代表了要读取的模板
			 File targetFile = new File(downpath+"/"+grade+".xls");
			 WritableWorkbook wwb = Workbook.createWorkbook(targetFile, wb);
			 // 第三步：选择模板中名称为StateResult的Sheet：
			 WritableSheet wws = wwb.getSheet(0);
			 // 第四步：选择单元格，写入动态值，根据单元格的不同类型转换成相应类型的单元格：
			 // (列，行)
			 Label A1 = (Label) wws.getWritableCell(0, 0);
			 A1.setString("温岭中学2012学年第二学期"+grade+"学生选修课第2时段安排");
			 Label A2 = (Label) wws.getWritableCell(0, 1);
			 A2.setString("04/24/12");
			 wwb.write();
			 wwb.close();
			 wb.close();
			 
			 
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		response.sendRedirect("../download");
		return null;
	}
}
